package pwd.allen.bytebuddy;

import net.bytebuddy.agent.builder.AgentBuilder;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.dynamic.DynamicType;
import net.bytebuddy.utility.JavaModule;

public class BytebuddyListener implements AgentBuilder.Listener {

    /**
     * 当某个类将要被加载时就会回调
     */
    @Override
    public void onDiscovery(String s, ClassLoader classLoader, JavaModule javaModule, boolean b) {
    }

    @Override
    public void onTransformation(TypeDescription typeDescription, ClassLoader classLoader, JavaModule javaModule, boolean b, DynamicType dynamicType) {
        System.out.println("onTransformation:" + typeDescription.getName());
    }

    @Override
    public void onIgnored(TypeDescription typeDescription, ClassLoader classLoader, JavaModule javaModule, boolean b) {
    }

    /**
     * 当bytebuddy在transform过程中发生异常时回调
     */
    @Override
    public void onError(String s, ClassLoader classLoader, JavaModule javaModule, boolean b, Throwable throwable) {
    }

    /**
     * 某个类处理完（包括transform ignore error）时回调
     * @param s
     * @param classLoader
     * @param javaModule
     * @param b
     */
    @Override
    public void onComplete(String s, ClassLoader classLoader, JavaModule javaModule, boolean b) {
    }
}
